gusucode.com > VC++ 汽配销售管理系统(Access)源码程序 > VC++ 汽配销售管理系统(Access)源码程序/源码/DBackFactry.cpp

    //Download by http://www.NewXing.com
// DBackFactry.cpp : implementation file
//

#include "stdafx.h"
#include "qpglxt.h"
#include "DBackFactry.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CDBackFactry dialog


CDBackFactry::CDBackFactry(CWnd* pParent /*=NULL*/)
	: CDialog(CDBackFactry::IDD, pParent)
{
	//{{AFX_DATA_INIT(CDBackFactry)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
}


void CDBackFactry::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CDBackFactry)
		// NOTE: the ClassWizard will add DDX and DDV calls here
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CDBackFactry, CDialog)
	//{{AFX_MSG_MAP(CDBackFactry)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CDBackFactry message handlers

void CDBackFactry::OnOK() 
{
	// TODO: Add extra validation here
	
	//CDialog::OnOK();
}

void CDBackFactry::Clear()
{
	this->m_EdtProvide.SetWindowText("");
	this->m_Grid.DeleteAllItems();
	this->m_EdtGiveChange.SetWindowText("0");
	this->m_EdtNoPay.SetWindowText("0");
	this->m_EdtPay.SetWindowText("0");
	this->m_StaBigSumMoney.SetWindowText("零元");
	this->m_StaSumMoney.SetWindowText("0");
	this->m_StaSumNumber.SetWindowText("0");

}

void CDBackFactry::Enabled(bool bEnabled)
{
	this->m_Grid.EnableWindow(!bEnabled);
	this->m_ButBookIn.EnableWindow(bEnabled);
	this->m_EdtPay.EnableWindow(!bEnabled);
	this->m_ButExit.EnableWindow(bEnabled);
	this->m_ButPrint.EnableWindow(bEnabled);
	this->m_ButSave.EnableWindow(!bEnabled);
	this->m_ButUndo.EnableWindow(!bEnabled);
}

void CDBackFactry::OnCellKillFocus()
{
	CString sNumber,sMoney,sTotal,sSumNumber,sSumMoney;
	int nTotal,nNumber,nSumNumber=0,nSumMoney=0;
	if(m_Grid.GetCol()==5)
	{
		sNumber=m_Grid.GetItemText(m_Grid.GetRow(),5);
		if(sNumber.IsEmpty())
		{
			m_Grid.m_Edit.EnterNumber=0;
			m_Grid.SetCol(5);
			m_Grid.BeginEdit(this->m_Grid.GetRow(),5);
			m_Grid.m_Edit.SetFocus();
		}
	}
	if(m_Grid.GetCol()==6)
	{
		sNumber=m_Grid.GetItemText(m_Grid.GetRow(),5);
		sMoney=m_Grid.GetItemText(m_Grid.GetRow(),6);
		nTotal=atoi(sNumber)*atoi(sMoney);
		sTotal.Format("%d",nTotal);
		m_Grid.SetItemText(m_Grid.GetRow(),7,sTotal);
		for(int i=0;i<m_Grid.GetRows();i++)
		{
			sNumber=m_Grid.GetItemText(i,5);
			sMoney=m_Grid.GetItemText(i,6);
			nNumber=atoi(sNumber);
			nTotal=nNumber*atoi(sMoney);
			nSumNumber=nSumNumber+nNumber;
			nSumMoney=nSumMoney+nTotal;
		}
		sSumNumber.Format("%d",nSumNumber);
		sSumMoney.Format("%d",nSumMoney);
		m_StaSumMoney.SetWindowText(sSumMoney);
		m_StaSumNumber.SetWindowText(sSumNumber);
		m_StaBigSumMoney.SetWindowText(MoneyToChineseCode(sSumMoney));
		this->m_EdtNoPay.SetWindowText(sSumMoney);
	}
}

void CDBackFactry::OnCellSetFocus()
{
	CString sSQL, sName,sType,sSpec,sAddr;
	switch(m_Grid.GetCol())
	{
	case 0:
		m_Grid.m_Edit.NumberOnly(false);
		m_Grid.m_Edit.PopHide=false;
		m_Grid.m_Edit.EnterNumber=0;     
		m_Grid.m_Edit.ClearAll();
		rst.Open("SELECT DISTINCT 名称,简称 from 商品信息表",adCmdText);		
		m_Grid.m_Edit.StartUpAssciation=true;
		m_Grid.m_Edit.SetRecordset(rst);
		m_Grid.m_Edit.SetSelectField("名称");
		m_Grid.m_Edit.AutoPosition();
		break;
	case 1:
		m_Grid.m_Edit.NumberOnly(false);
		m_Grid.m_Edit.PopHide=false;
		m_Grid.m_Edit.EnterNumber=0;     
		m_Grid.m_Edit.ClearAll();
		sName=m_Grid.GetItemText(m_Grid.GetRow(),0);
		sSQL.Format("SELECT DISTINCT 名称,适用车型 from 商品信息查询 WHERE 名称='%s'",sName);
		rst.Open(sSQL,adCmdText);		
		m_Grid.m_Edit.StartUpAssciation=false;
		m_Grid.m_Edit.SetRecordset(rst);
		m_Grid.m_Edit.SetSelectField("适用车型");
		m_Grid.m_Edit.AutoPosition();
		break;

	case 2:
		m_Grid.m_Edit.NumberOnly(false);
		m_Grid.m_Edit.PopHide=false;
		m_Grid.m_Edit.EnterNumber=0;     
		m_Grid.m_Edit.ClearAll();
		sName=m_Grid.GetItemText(m_Grid.GetRow(),0);
		sType=m_Grid.GetItemText(m_Grid.GetRow(),1);
		sSQL.Format("SELECT DISTINCT 名称,规格 from 商品信息查询 WHERE 名称='%s' AND 适用车型='%s'",sName,sType);
		rst.Open(sSQL,adCmdText);		
		m_Grid.m_Edit.StartUpAssciation=false;
		m_Grid.m_Edit.SetRecordset(rst);
		m_Grid.m_Edit.SetSelectField("规格");
		m_Grid.m_Edit.AutoPosition();
		break;

	case 3:
		m_Grid.m_Edit.NumberOnly(false);
		m_Grid.m_Edit.PopHide=false;
		m_Grid.m_Edit.EnterNumber=0;     
		m_Grid.m_Edit.ClearAll();
		sName=m_Grid.GetItemText(m_Grid.GetRow(),0);
		sType=m_Grid.GetItemText(m_Grid.GetRow(),1);
		sSpec=m_Grid.GetItemText(m_Grid.GetRow(),2);
		sSQL.Format("SELECT DISTINCT 名称,产地 from 商品信息查询 WHERE 名称='%s' AND 适用车型='%s' AND 规格='%s'",sName,sType,sSpec);
		rst.Open(sSQL,adCmdText);		
		m_Grid.m_Edit.StartUpAssciation=false;
		m_Grid.m_Edit.SetRecordset(rst);
		m_Grid.m_Edit.SetSelectField("产地");
		m_Grid.m_Edit.AutoPosition();
		break;
	case 4:
		m_Grid.m_Edit.NumberOnly(false);
		m_Grid.m_Edit.PopHide=false;
		m_Grid.m_Edit.EnterNumber=0;     
		m_Grid.m_Edit.ClearAll();
		sName=m_Grid.GetItemText(m_Grid.GetRow(),0);
		sType=m_Grid.GetItemText(m_Grid.GetRow(),1);
		sSpec=m_Grid.GetItemText(m_Grid.GetRow(),2);
		sAddr=m_Grid.GetItemText(m_Grid.GetRow(),3);
		sSQL.Format("SELECT DISTINCT 名称,计量单位 from 商品信息查询 WHERE 名称='%s' AND 适用车型='%s' AND 规格='%s' AND 产地='%s'",sName,sType,sSpec,sAddr);
		rst.Open(sSQL,adCmdText);		
		m_Grid.m_Edit.StartUpAssciation=false;
		m_Grid.m_Edit.SetRecordset(rst);
		m_Grid.m_Edit.SetSelectField("计量单位");
		m_Grid.m_Edit.AutoPosition();
		break;
	case 5:
		m_Grid.m_Edit.PopHide=true;
		m_Grid.m_Edit.NumberOnly(true);
		m_Grid.m_Edit.HideGrid();
		break;
	case 6:
		m_Grid.m_Edit.PopHide=false;
		m_Grid.m_Edit.EnterNumber=0;     
		m_Grid.m_Edit.ClearAll();
		m_Grid.m_Edit.NumberOnly(true);
		sName=m_Grid.GetItemText(m_Grid.GetRow(),0);
		sType=m_Grid.GetItemText(m_Grid.GetRow(),1);
		sSpec=m_Grid.GetItemText(m_Grid.GetRow(),2);
		sAddr=m_Grid.GetItemText(m_Grid.GetRow(),3);
		sSQL.Format("SELECT DISTINCT 名称,进价 from 商品信息查询 WHERE 名称='%s' AND 适用车型='%s' AND 规格='%s' AND 产地='%s'",sName,sType,sSpec,sAddr);
		rst.Open(sSQL,adCmdText);		
		m_Grid.m_Edit.StartUpAssciation=false;
		m_Grid.m_Edit.SetRecordset(rst);
		m_Grid.m_Edit.SetSelectField("进价");
		m_Grid.m_Edit.AutoPosition();
		m_Grid.m_Edit.ShowGrid();
		break;
	case 7:
		m_Grid.m_Edit.EnterNumber=0;
		m_Grid.m_Edit.PopHide=true;
		m_Grid.m_Edit.NumberOnly(true);
		m_Grid.m_Edit.HideGrid();
		break;

	}
}